package com.timous.数组;

/**
 *https://leetcode-cn.com/problems/two-sum/
 */
public class _1_两数之和 {

    public static void main(String[] args) {
        int[] nums = new int[]{2, 7, 11, 15};
        int target = 9;
        int[] ints = twoSum(nums, target);
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }
    }

    public static int[] twoSum(int[] nums, int target) {
        int[] array = new int[2];
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if(target == nums[i] + nums[j]){
                    for (int i1 = 0; i1 < array.length; i1++) {
                        array[0] = i;
                        array[1] = j;
                    }
                    break;
                }
            }
        }
        return array;
    }

    /**
     * 优化： 使用hashmap 来进行判断
     * 一个数组
     * [a1 , a2 , a3]
     * 在hashmap中存放  target - array[i]   进行判断   看之前的hashmap中是不是包含这个值
     */

}
